//===============================================================================
// Microsoft patterns & practices
// Web Service Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.VisualStudio.Modeling.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace Microsoft.Practices.Modeling.Dsl.Integration.Helpers
{
	// FXCOP: False positive
	[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
	internal class DesignerHelper
    {
		public static SingleDiagramDocView GetWindowFrameProperty(IServiceProvider provider, __VSFPROPID propertyId)
        {
            IVsMonitorSelection selection = (IVsMonitorSelection)provider.GetService(typeof(IVsMonitorSelection));
            if(selection != null)
            {
                object frameObject;
                selection.GetCurrentElementValue(2, out frameObject);

                IVsWindowFrame windowFrame = frameObject as IVsWindowFrame;
                if(windowFrame != null)
                {
                    object propertyValue;
                    windowFrame.GetProperty((int)propertyId, out propertyValue);
					return propertyValue as SingleDiagramDocView;
                }
            }

            return null;
        }

        public static SingleDiagramDocView GetModelDocView(IServiceProvider provider)
        {
            return GetWindowFrameProperty(provider, __VSFPROPID.VSFPROPID_DocView);
        }
    }
}
